/*
 * Copyright (c) 2006, 2021, webrx.cn All rights reserved.
 *
 */
package cn.webrx;

import java.util.Random;
import java.util.Scanner;

/**
 * <p>Project: javase - Day7
 * <p>Powered by webrx On 2021-11-29 15:04:47
 *
 * @author webrx [webrx@126.com]
 * @version 1.0
 * @since 17
 */
public class Day7 {
    public static void main(String[] args) {
        //猜数字游戏
        System.out.println("欢迎来到猜数字游戏！！！");
        System.out.println("请输入1-100之间的数字.");
        Random num = new Random();
        int i = num.nextInt(100) + 1;
        //System.out.println(i);
        Scanner put = new Scanner(System.in);
        for (int j = 1; j <= 11; j++) {
            if (j > 10) {
                System.out.println("您猜的次数超过10次了，游戏结束！！！智商欠缺，建议喝六个核桃！！！");
                break;
            }
            System.out.printf("请输入数字：");

            String putin = put.next();
            int putinn = 0;
            try {
                putinn = Integer.parseInt(putin);
            } catch (Exception e) {
                System.out.println("您输入的不是数字，请重新输入！！！");
                continue;
            }

            if (putinn > i) {
                System.out.println("您输入的数字偏大！请重试！！");
            }
            if (putinn < i) {
                System.out.println("您输入的数字偏小！请重试！！");
            }
            if (putinn == i) {
                System.out.println("恭喜您猜对了！！！");
                break;
            }
        }
    }
}
